package com.oracle.sbdb.bo;

import java.util.HashMap;
import java.util.Map;

import com.oracle.sbdb.dao.ProductDao;
import com.oracle.sbdb.model.Product;

public class ProductBo {
	public static ProductBo INSTANCE = new ProductBo();

	private static ProductDao productDao = new ProductDao();

	private static Map<Integer, Product> productMap = new HashMap<Integer, Product>();

	private ProductBo() {
	};

	public String getProductNamebyID(int productId) {
		String res = null;
		
		if (productMap.containsKey(productId)) {
			res = productMap.get(productId).getProduct_name();
		} else {
			Product product = productDao.selectbyId(productId);
			if (product != null) {
				productMap.put(productId, product);
				res = product.getProduct_name();
			}
		}
		
		return res;
	}
}
